/*
package com.own.demo.lwf.utils.workUtils;
package com.own.demo.workUtils;

import cn.hsa.cep.plc.std.common.adapt.dict.entity.DataDictDO;
import cn.hsa.cep.plc.std.common.adapt.dict.entity.TaDictCache;
import cn.hsa.cep.plc.std.common.adapt.dict.util.DictUtils;
import cn.hsa.hsaf.core.framework.context.HsafContextHolder;
import cn.hsa.hsaf.core.framework.util.CurrentUser;
import cn.hsa.mbs.common.exception.MbsException;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.util.ReflectionUtils;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
public class ExcelXSSFUtil {

    private static final String NOT_EDIT = "1";


*/
/**
     * 导出数据
     *
     * @param headName 列名
     * @param headId   列ID,如果有字典，以：区分，如gend:gend
     * @param list     数据
     * @param fileName 文件名
     * @param response 响应
     * @throws java.lang.Exception
     *//*


    public static void exportExcelData(String[] headName, String[] headId, List list, String fileName, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFWorkbook workbook = null;
        ServletOutputStream outputStream = null;
        try{
            workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.createSheet("个人账户清算信息");

            //将单元格格式设置为"文本"格式
            XSSFCellStyle cellStyle_text = workbook.createCellStyle();
            XSSFDataFormat dataFormat_text = workbook.createDataFormat();
            cellStyle_text.setDataFormat(dataFormat_text.getFormat("@"));

            XSSFRow rowHead = sheet.createRow(0);
            for (int j = 0; j < headName.length; j++) {
                XSSFCell cell = rowHead.createCell(j);
                cell.setCellStyle(cellStyle_text);
                cell.setCellValue(headName[j]);
            }
            Object obj = null;
            Map map = new HashMap();
            for (int i = 1; i <= list.size(); i++) {
                XSSFRow row = sheet.createRow(i);
                obj = list.get(i - 1);
                map = FileImportExportUtil.objToMap(obj);
                for (int j = 0; j < headId.length; j++) {
                    XSSFCell cell = row.createCell(j);
                    cell.setCellStyle(cellStyle_text);
                    XSSFRichTextString text = null;
                    String[] headstrs = headId[j].split(":");
                    String head = null;
                    String dictName = null;
                    if (headstrs.length > 1) {
                        head = (String) map.get(headstrs[0]);
                        dictName = headstrs[1];
                    } else {
                        head = (String) map.get(headId[j]);
                    }
                    if ("".equals(head) || head == null) {
                        text = new XSSFRichTextString("");
                    } else if (dictName != null && !dictName.equals("")) {
                        // !StringUtils.isNullOrEmpty(dictName) 奇安信代码扫描无法通过
                        head = BaseUtil.getDict(dictName, head);
                        text = new XSSFRichTextString(head);
                    } else {
                        if ("optTime".equals(headId[j])) {
                            Date date = new Date(head);
                            String a = sdf.format(date);
                            text = new XSSFRichTextString(a);
                        }else{
                            text = new XSSFRichTextString(head);
                        }
                    }
                    cell.setCellValue(text);
                }
            }


            response.setContentType("application/octet-stream;charset=UTF-8");
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setCharacterEncoding("UTF-8");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
            workbook.close();
            outputStream.flush();
            outputStream.close();
        }
        catch (Exception e){
            throw new MbsException(e.getMessage());
        }
        finally {
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
        }
    }

*/
/**
     * 导出数据
     *
     * @param headName 列名
     * @param headId   列ID,如果有字典，以：区分，如gend:gend
     * @param list     数据
     * @param fileName 文件名
     * @param response 响应
     * @throws java.lang.Exception
     *//*


    public static void exportExcel(String[] headName, String[] headId, List list, String fileName, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFWorkbook workbook = null;
        ServletOutputStream outputStream = null;
        try{
            workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("sheet1");

        //将单元格格式设置为"文本"格式
        XSSFCellStyle cellStyle_text = workbook.createCellStyle();
        XSSFDataFormat dataFormat_text = workbook.createDataFormat();
        cellStyle_text.setDataFormat(dataFormat_text.getFormat("@"));

        XSSFRow rowHead = sheet.createRow(0);
        for (int j = 0; j < headName.length; j++) {
            XSSFCell cell = rowHead.createCell(j);
            cell.setCellStyle(cellStyle_text);
            cell.setCellValue(headName[j]);
            String headstrs[] = headId[j].split(":");
            if (headstrs.length > 1) {
                List<String> labels = new ArrayList<>();
                if ("psnType".equals(headstrs[0])) {
                    labels.add("新生儿");
                    labels.add("学龄前儿童");
                    labels.add("中小学生");
                    labels.add("大学生");
                    labels.add("未成年（未入学）");
                    labels.add("普通居民（成年）");
                    labels.add("居民（成年）");
                    labels.add("居民（老年）");
                    labels.add("其他");
                } else {
                    labels = BaseUtil.getDictLabels(headstrs[1]);
                }
                if (labels != null && labels.size() > 0) {
                    addValidate(sheet, labels, headName[j], j);
                }
            }
        }
        Object obj = null;
        Map map = new HashMap();
        for (int i = 1; i <= list.size(); i++) {
            XSSFRow row = sheet.createRow(i);
            obj = list.get(i - 1);
            map = FileImportExportUtil.objToMap(obj);
            for (int j = 0; j < headId.length; j++) {
                XSSFCell cell = row.createCell(j);
                cell.setCellStyle(cellStyle_text);
                XSSFRichTextString text = null;
                String[] headstrs = headId[j].split(":");
                String head = null;
                String dictName = null;
                if (headstrs.length > 1) {
                    head = (String) map.get(headstrs[0]);
                    dictName = headstrs[1];
                } else {
                    head = (String) map.get(headId[j]);
                }
                if ("".equals(head) || head == null) {
                    text = new XSSFRichTextString("");
                } else if (dictName != null && !dictName.equals("")) {
                    // !StringUtils.isNullOrEmpty(dictName) 奇安信代码扫描无法通过
                    head = BaseUtil.getDict(dictName, head);
                    text = new XSSFRichTextString(head);
                } else {
                    if ("brdy".equals(headId[j])) {
                        Date date = new Date(head);
                        String a = sdf.format(date);
                        text = new XSSFRichTextString(a);
                    } else {
                        text = new XSSFRichTextString(head);
                    }
                }
                cell.setCellValue(text);
            }
        }

        //将单元格格式设置为"文本"格式
        sheet.setColumnWidth(0, 6000);
        sheet.setColumnWidth(3, 6000);
        sheet.setColumnWidth(6, 6000);
        sheet.setColumnWidth(8, 3500);
        sheet.setDefaultColumnStyle(0,cellStyle_text);
        sheet.setDefaultColumnStyle(3,cellStyle_text);
        sheet.setDefaultColumnStyle(6,cellStyle_text);
        sheet.setDefaultColumnStyle(8,cellStyle_text);

        response.setContentType("application/octet-stream;charset=UTF-8");
        response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
        response.setCharacterEncoding("UTF-8");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
            workbook.close();
            outputStream.flush();
            outputStream.close();
        }
        catch (Exception e){
            throw new MbsException(e.getMessage());
        }
        finally {
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
        }
    }


*/
/**
     * excel导出数据,个别列不可编辑  密码 123456
     *
     * @param headName         列名
     * @param headId           列ID,如果有字典，以：区分，如gend:gend
     * @param list             数据
     * @param fileName         文件名
     * @param response         响应
     * @param notEditColumnMap 不可编辑列 value="1" 表示不可编辑
     * @throws java.lang.Exception
     *//*


    public static void exportExcelwithColumnNotEdit(String[] headName, String[] headId, List list, String fileName, HttpServletResponse response, Map<String, String> notEditColumnMap) throws Exception {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFWorkbook workbook = null;
        ServletOutputStream outputStream = null;
        try{
            workbook = new XSSFWorkbook();
            //单元格格式锁定
            XSSFCellStyle lockStyle = workbook.createCellStyle();
            lockStyle.setLocked(true);
            lockStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            lockStyle.setFillForegroundColor(IndexedColors.RED1.index);
            //单元格格式不锁定
            XSSFCellStyle unlockStyle = workbook.createCellStyle();
            unlockStyle.setLocked(false);
            XSSFSheet sheet = workbook.createSheet("sheet1");
            XSSFRow rowHead = sheet.createRow(0);
            for (int j = 0; j < headName.length; j++) {
                sheet.setColumnWidth(j, 100);
                XSSFCell cell = rowHead.createCell(j);
                cell.setCellValue(headName[j]);
                String headstrs[] = headId[j].split(":");
                if (headstrs.length > 1) {
                    List<String> labels = BaseUtil.getDictLabels(headstrs[1]);
                    if (labels != null && labels.size() > 0) {
                        addValidate(sheet, labels, headName[j], j);
                    }
                }
            }
            Object obj = null;
            Map map = new HashMap();
            for (int i = 1; i <= list.size(); i++) {
                XSSFRow row = sheet.createRow(i);
                obj = list.get(i - 1);
                map = FileImportExportUtil.objToMap(obj);
                for (int j = 0; j < headId.length; j++) {
                    XSSFCell cell = row.createCell(j);
                    XSSFRichTextString text = null;
                    String[] headstrs = headId[j].split(":");
                    String head = null;
                    String dictName = null;
                    if (headstrs.length > 1) {
                        head = (String) map.get(headstrs[0]);
                        dictName = headstrs[1];
                    } else {
                        head = (String) map.get(headId[j]);
                    }
                    if (NOT_EDIT.equals(notEditColumnMap.get(headstrs[0]))) {
                        cell.setCellStyle(lockStyle);
                    } else {
                        cell.setCellStyle(unlockStyle);
                    }
                    if ("".equals(head) || head == null) {
                        text = new XSSFRichTextString("");
                    } else if (dictName != null && !dictName.equals("")) {
                        // !StringUtils.isNullOrEmpty(dictName) 奇安信代码扫描无法通过
                        head = BaseUtil.getDict(dictName, head);
                        text = new XSSFRichTextString(head);
                    } else {
                        if ("brdy".equals(headId[j])) {
                            Date date = new Date(head);
                            String a = sdf.format(date);
                            text = new XSSFRichTextString(a);
                        } else {
                            text = new XSSFRichTextString(head);
                        }
                    }
                    cell.setCellValue(text);
                }
            }
            sheet.protectSheet("123456");
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setCharacterEncoding("UTF-8");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
            workbook.close();
            outputStream.flush();
            outputStream.close();
        }
        catch (Exception e){
            throw new MbsException(e.getMessage());
        }
        finally {
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
        }
    }

    private static void addValidate(XSSFSheet sheet, List<String> list, String head, int column) {
        String str[] = list.toArray(new String[list.size()]);
        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
        XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(str);
        CellRangeAddressList addressList = new CellRangeAddressList(1, 5000, column, column);
        XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
        validation.setShowErrorBox(true);
        validation.createErrorBox("警告", head + "选择有误");
        sheet.addValidationData(validation);
    }

*/
/**
     * @param is    输入流
     * @param heads 对应列id,如果有字典：符号分割；如 gend:gend
     * @param c     对应DTO.class
     * @param jump  跳过的行数；
     * @return
     *//*


    public static List excelTOList(InputStream is, String[] heads, Class<?> c, int jump) throws Exception {
        List list = new ArrayList();
        try(XSSFWorkbook wb = new XSSFWorkbook(OPCPackage.open(is))) {
            //OPCPackage pkg = OPCPackage.open(is);
            //XSSFWorkbook wb = new XSSFWorkbook(pkg);
            XSSFSheet sheet = wb.getSheetAt(0);
            for (Row row : sheet) {
                if (row.getRowNum() < jump) {
                    continue;
                }
                Object obj = c.newInstance();
                for (Cell cell : row) {
                    if (cell.getCellTypeEnum() != CellType.BLANK) {
                        setFieldValue(obj, cell, heads, c);
                    }
                }
                list.add(obj);
            }
        } catch (Exception e) {
            throw new MbsException(e.getMessage());
        }
        return list;
    }

    private static void setFieldValue(Object obj, Cell cell, String[] heads, Class<?> c) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
        String[] dict = heads[cell.getColumnIndex()].split(":");
        String head = dict[0];
        Field field = c.getDeclaredField(head);
        ReflectionUtils.makeAccessible(field);
        switch (cell.getCellTypeEnum()) {
            case STRING:
                if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.util.Date")) {
                    field.set(obj, sdf.parse(cell.getStringCellValue()));
                } else if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.sql.Timestamp")) {
                    field.set(obj, Timestamp.valueOf(cell.getStringCellValue()));
                } else if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.math.BigDecimal")) {
                    field.set(obj, new BigDecimal(cell.getStringCellValue()));
                } else if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.lang.Integer")) {
                    field.set(obj, Integer.valueOf(cell.getStringCellValue()));
                } else if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.lang.Double")) {
                    field.set(obj, Double.valueOf(cell.getStringCellValue()));
                } else {
                    if (dict.length > 1) {
                        //如果是查*医保参保区划 需要单独处理,因为县区的名称各地市有重复的
                        if ("ADMDVS".equals(dict[1])) {
                            String label = "";
                            CurrentUser user = HsafContextHolder.getContext().getCurrentUser();
                            String admdvs = user.getAdmDvs().substring(0, 2);
                            List<DataDictDO> list = DictUtils.getCodeList(dict[1], "1");
                            list = list.stream().filter(t -> {
                                return t.getValue().substring(0, 2).equals(admdvs);
                            }).collect(Collectors.toList());

                            if (ValidateUtil.isEmpty(list)) {

                            } else {
                                for (DataDictDO dataDictDO : list) {
                                    if (cell.getStringCellValue().equals(dataDictDO.getLabel())) {
                                        label = dataDictDO.getValue();
                                    }
                                }
                            }
                            if (label == null) {
                                field.set(obj, cell.getStringCellValue());
                            } else {
                                field.set(obj, label);
                            }
                        } else {
                            String label = BaseUtil.getDictCode(dict[1], cell.getStringCellValue());
                            if (label == null) {
                                field.set(obj, cell.getStringCellValue());
                            } else {
                                field.set(obj, label);
                            }
                        }

                    } else {
                        field.set(obj, cell.getStringCellValue());
                    }
                }
                break;
            case NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    field.set(obj, cell.getDateCellValue());
                } else {
                    if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.math.BigDecimal")) {
                        //field.set(obj, new BigDecimal(cell.getNumericCellValue()));
                        field.set(obj, BigDecimal.valueOf(cell.getNumericCellValue()));
                    } else if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.lang.Integer")) {
                        Double a = cell.getNumericCellValue();
                        field.set(obj, a.intValue());
                    } else if (ValidateUtil.areEqual(field.getGenericType().toString(), "class java.lang.String")) {
                        String str = new DecimalFormat("#").format(cell.getNumericCellValue());
                        field.set(obj, str);
                    } else {
                        field.set(obj, cell.getNumericCellValue());
                    }
                }
                break;
            case BOOLEAN:
                field.set(obj, cell.getBooleanCellValue());
                break;
            case BLANK:
                field.set(obj, "");
                break;
            default:
                field.set(obj, cell.toString());
                break;
        }
    }

    public static void exportXlsx(String[] headName, String[] headId, List list, String fileName, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFWorkbook workbook = null;
        ServletOutputStream outputStream = null;
        try{
            workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("sheet1");
        XSSFRow rowHead = sheet.createRow(0);
        for (int j = 0; j < headName.length; j++) {
            XSSFCell cell = rowHead.createCell(j);
            cell.setCellValue(headName[j]);
            String headstrs[] = headId[j].split(":");
            if (headstrs.length > 1) {
                List<String> labels = new ArrayList<>();
                if ("matIdetCode".equals(headstrs[0])) {
                    labels.add("最低生活保障家庭成员");
                    labels.add("特困供养人员");
                    labels.add("具有本地户籍的临时救助对象中的大重病患者");
                    labels.add("享受民政定期定量补助费的20世纪60年供精减退职职工");
                    labels.add("重点优抚对象中的孤老");
                    labels.add("重点优抚对象中的其他对象");
                    labels.add("困境儿童中的孤儿");
                    labels.add("困境儿童中的其他对象");
                    labels.add("总工会核定的特困职工");
                    labels.add("建档立卡低收入人口");
                    labels.add("参加居民基本医疗保险的二级以上重度残疾人");
                    labels.add("军烈属");
                    labels.add("建档立卡低收入人员");
                    labels.add("家庭经济困难的精神障碍患者、肇事肇祸的精神障碍患者");
                    labels.add("精神病患者");
                    labels.add("严重精神障碍人员");
                } else {
                    labels = BaseUtil.getDictLabels(headstrs[1]);
                }
                if (labels != null && labels.size() > 0) {
                    addValidate(sheet, labels, headName[j], j);
                }
            }
        }
        Object obj = null;
        Map map;
        for (int i = 1; i <= list.size(); i++) {
            XSSFRow row = sheet.createRow(i);
            obj = list.get(i - 1);
            map = FileImportExportUtil.objToMap(obj);
            for (int j = 0; j < headId.length; j++) {
                XSSFCell cell = row.createCell(j);
                XSSFRichTextString text = null;
                String[] headstrs = headId[j].split(":");
                String head = null;
                String dictName = null;
                if (headstrs.length > 1) {
                    head = (String) map.get(headstrs[0]);
                    dictName = headstrs[1];
                } else {
                    head = (String) map.get(headId[j]);
                }
                if ("".equals(head) || head == null) {
                    text = new XSSFRichTextString("");
                } else if (dictName != null && !dictName.equals("")) {
                    head = BaseUtil.getDict(dictName, head);
                    text = new XSSFRichTextString(head);
                } else {
                    Field field = obj.getClass().getDeclaredField(headId[j]);
                    boolean b = field.isAccessible();
                    field.setAccessible(true);
                    if (field.get(obj) instanceof Date) {
                        String a = sdf.format(field.get(obj));
                        text = new XSSFRichTextString(a);
                    } else {
                        text = new XSSFRichTextString(head);
                    }
                    field.setAccessible(b);
                }
                cell.setCellValue(text);
            }
        }
        response.setContentType("application/octet-stream;charset=UTF-8");
        response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
        response.setCharacterEncoding("UTF-8");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
            workbook.close();
            outputStream.flush();
            outputStream.close();
        }
        catch (Exception e){
            throw new MbsException(e.getMessage());
        }
        finally {
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
        }
    }

    public static void exportXlsx(String[] headName, String[] headId, Map<String, TaDictCache> dicMap, List list, String fileName, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFWorkbook workbook = null;
        ServletOutputStream outputStream = null;
        try{
            workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.createSheet("sheet1");
            XSSFRow rowHead = sheet.createRow(0);
            for (int j = 0; j < headName.length; j++) {
                XSSFCell cell = rowHead.createCell(j);
                cell.setCellValue(headName[j]);
                String headstrs[] = headId[j].split(":");
                if (headstrs.length > 1) {
                    //List<String> labels = BaseUtil.getDictLabels(headstrs[1]);
                    List<String> labels = dicMap.get(headstrs[1]).getList().stream().map(DataDictDO::getLabel).collect(Collectors.toList());
                    if (labels != null && labels.size() > 0) {
                        addValidate(sheet, labels, headName[j], j);
                    }
                }
            }
            Object obj = null;
            Map map;
            for (int i = 1; i <= list.size(); i++) {
                XSSFRow row = sheet.createRow(i);
                obj = list.get(i - 1);
                map = FileImportExportUtil.objToMap(obj);
                for (int j = 0; j < headId.length; j++) {
                    XSSFCell cell = row.createCell(j);
                    XSSFRichTextString text = null;
                    String[] headstrs = headId[j].split(":");
                    String head = null;
                    String dictName = null;
                    if (headstrs.length > 1) {
                        head = (String) map.get(headstrs[0]);
                        dictName = headstrs[1];
                    } else {
                        head = (String) map.get(headId[j]);
                    }
                    if ("".equals(head) || head == null) {
                        text = new XSSFRichTextString("");
                    } else if (dictName != null && !dictName.equals("")) {
                        head = BaseUtil.getDict(dictName, head, dicMap);
                        text = new XSSFRichTextString(head);
                    } else {
                        Field field = obj.getClass().getDeclaredField(headId[j]);
                        boolean b = field.isAccessible();
                        field.setAccessible(true);
                        if (field.get(obj) instanceof Date) {
                            String a = sdf.format(field.get(obj));
                            text = new XSSFRichTextString(a);
                        } else {
                            text = new XSSFRichTextString(head);
                        }
                        field.setAccessible(b);
                    }
                    cell.setCellValue(text);
                }
            }
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setCharacterEncoding("UTF-8");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
            workbook.close();
            outputStream.flush();
            outputStream.close();
        }
        catch (Exception e){
            throw new MbsException(e.getMessage());
        }
        finally {
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(),e);
                }
            }
        }
    }
}

*/
